package com.mowh.gof23.structural.patterns.facade.pagemaker;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

/**
 * @author mowh1gd
 * @create 2023/10/25 17:11
 */
public class PageMaker {
    private PageMaker() {
    }
    public static void makeWelcomePage(String mailAddress, String fileName) {
        Properties mailProperties = Database.getProperties(PageMaker.class.getClassLoader().getResource("facade/maildata.txt").getPath());
        String userName = mailProperties.getProperty(mailAddress);
        try {
            HtmlWriter htmlWriter = new HtmlWriter(new FileWriter(PageMaker.class.getClassLoader().getResource("facade").getPath() + "/" + fileName));
            htmlWriter.title("Welcome to " + userName + "'s page!");
            htmlWriter.paragraph(userName + " 欢迎来到 " + userName + " 的主页");
            htmlWriter.paragraph("等着你的邮件哦！");
            htmlWriter.mailTo(mailAddress, userName);
            htmlWriter.close();
            System.out.println(fileName + " is created for " + mailAddress + "(" + userName + ")");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
